const os = require("os");

function getLocalIP() {
  const networkInterfaces = os.networkInterfaces();

  for (const interfaceKey in networkInterfaces) {
    const networkInterface = networkInterfaces[interfaceKey];

    for (let i = 0; i < networkInterface.length; i++) {
      const network = networkInterface[i];

      // 排除IPv6地址和内部/私有地址
      if (network.family === "IPv4" && !network.internal) {
        return network.address;
      }
    }
  }

  return null; // 如果没有找到合适的IPv4地址，返回null
}
module.exports = getLocalIP;

